/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.cezary.butler.walili.server;

import pl.cezary.butler.walili.common.Task;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 *
 * @author Cezary Butler
 */
class TaskSet implements Set<Task> {

    private class ZadanieTimeWrapper{
        
        public ZadanieTimeWrapper(Task z){
            militime = System.currentTimeMillis();
            zadanie = z;
        }
        
        private Task zadanie;
        private long militime;
        
        long getTime(){
            return militime;            
        }
        
        Task getZadanie(){
            return zadanie;
        }
        
    }
    
    //private ConcurrentHashMap<ZadanieSerwer, ZadanieSerwer> source = new ConcurrentHashMap<ZadanieSerwer, ZadanieSerwer>();
    private ConcurrentHashMap<Task, ZadanieTimeWrapper> source = new ConcurrentHashMap<Task, ZadanieTimeWrapper>();

    @Override
    public int size() {
        return source.size();
    }

    @Override
    public boolean isEmpty() {
        return source.isEmpty();
    }

    @Override
    public boolean contains(Object arg0) {
        return source.containsKey(arg0);
    }

    @Override
    public Iterator<Task> iterator() {
        return source.keySet().iterator();            
    }

    @Override
    public Object[] toArray() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public <T> T[] toArray(T[] arg0) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean add(Task arg0) {
        //source.put(arg0, arg0);
        source.put(arg0, new ZadanieTimeWrapper(arg0));
        return true;
    }

    @Override
    public boolean remove(Object arg0) {
        source.remove(arg0);
        return true;
    }

    @Override
    public boolean containsAll(Collection<?> arg0) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean addAll(Collection<? extends Task> arg0) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean retainAll(Collection<?> arg0) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean removeAll(Collection<?> arg0) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void clear() {
        source.clear();
    }

    public Task get(Task zad) {
        return source.get(zad).getZadanie();
    }
    
    public long getTime(Task zad) {
        return source.get(zad).getTime();
    }
}
